package cn.edu.lingnan.service.impl;

import cn.edu.lingnan.common.JsonResult;
import cn.edu.lingnan.entity.Admin;
import cn.edu.lingnan.mapper.AdminMapper;
import cn.edu.lingnan.service.AdminService;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.web.servlet.server.Session;
import org.springframework.stereotype.Service;

/**
 * <p>
 *  服务实现类
 * </p>
 *
 * @author 文韬
 * @since 2022-06-24
 */
@Service
public class AdminServiceImpl extends ServiceImpl<AdminMapper, Admin> implements AdminService {

    //注入持久层对象到业务层中使用
    @Autowired(required = false)
    private AdminMapper adminMapper;
    @Override
    public JsonResult<Void> adminLogin(String aAccount, String aPassWord, Session session) {

        //验证账号
        if ("".equals(aAccount) || aAccount == null){
            return new JsonResult<>(201,"账号不能为空");
        }
        QueryWrapper<Admin> queryWrapper = new QueryWrapper<>();
        queryWrapper.eq("a_account",aAccount);
        Admin admin = adminMapper.selectOne(queryWrapper);
        if (admin == null){
            return new JsonResult<>(202,"此管理员账号不存在");
        }

        //验证密码
        if ("".equals(aPassWord) || aPassWord == null){
            return new JsonResult<>(203,"密码不能为空");
        }
        if (admin.getAPassWord().equals(aPassWord) == false){
            return new JsonResult<>(204,"密码错误");
        }
        return new JsonResult<>(200,"登录成功");
    }

}
